package com.rem.springIocXml.helloWorld;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


/**
 * @author Rem
 * @date 2023/2/26
 */
public class HelloWorldTest {

    private final Logger logger = LoggerFactory.getLogger(HelloWorldTest.class);

    @Test
    public void testHelloWorld() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("helloword.xml");
        //根据类型获取
        HelloWorld helloworld = applicationContext.getBean(HelloWorld.class);
        //根据beanId获取
        HelloWorld helloworld2 = applicationContext.getBean("hello", HelloWorld.class);
        //根据类型和beanId获取
        HelloWorld helloworld3 = (HelloWorld) applicationContext.getBean("hello");
        System.out.println(helloworld.hashCode());
        System.out.println(helloworld2.hashCode());
        System.out.println(helloworld3.hashCode());
        helloworld.say();
        helloworld2.say();
        helloworld3.say();
        logger.info("执行成功");
    }
}